package Algorithm.Search.BasicSearch;

import java.util.ArrayList;

public class BasicSearchWithRepetition {
    public static void main(String[] args) {
        int[] arr = {1, 2, 3, 4, 5, 6, 1, 5, 2, 1};
        for(int i : Search(arr,1)){
            System.out.println(i);
        }
    }

    public static int[] Search(int[] arr, int target) {
        ArrayList<Integer> list = new ArrayList<>();
        for (int i = 0; i < arr.length; i++)
            if (target == arr[i])
                list.add(i);
        return ArrayListToArray(list);
    }

    public static int[] ArrayListToArray(ArrayList<Integer> list) {
        int[] arr = new int[list.size()];
        for (int i = 0; i < list.size(); i++) {
            arr[i] = list.get(i);
        }
        return arr;
    }
}
